﻿using System;
using System.Collections.Generic;
using System.Text;

using Kitware.VTK;

namespace Fu3DEngine
{
    public class SphereNode : CPNodeBase 
    {
       CPSphere m_ent;
       public SphereNode(CPSphere  sphere,string id):base(id)
       {
           m_ent = sphere;
       }

       public override void Run()
       {
           base.Run();

           this.CreateSphere(m_ent);
          
       }

       public override void ReLoad()
       {
           throw new NotImplementedException();
       }

       public void CreateSphere(CPSphere cy)
       {
           vtkSphereSource cylinder = new vtkSphereSource();

           cylinder.SetRadius(cy.radius);
           cylinder.SetPhiResolution(12);
           cylinder.SetThetaResolution(12);

          // cylinder.SetCenter(0, -cy.radius, 0);
           cylinder.SetCenter(0, 0, 0);

           vtkTransform tran = new vtkTransform();
           tran.RotateX(90);


           vtkTransformFilter tf = new vtkTransformFilter();
           tf.SetInput(cylinder.GetOutput());
           tf.SetTransform(tran);





        
           m_Poly.m_Mapper.SetInput(tf.GetPolyDataOutput());








           m_Poly.m_Actor.SetPosition(cy.x, cy.y, cy.z);

           m_Poly.m_Actor.GetProperty().SetAmbientColor(cy.m_color.R, cy.m_color.G, cy.m_color.B);
           m_Poly.m_Actor.GetProperty().SetDiffuseColor(cy.m_color.R, cy.m_color.G, cy.m_color.B);



           this.SParent.m_vtkRenderer.AddActor(m_Poly.m_Actor);
       }

    }
}
